﻿<%@ WebHandler Language="C#" Class="getmymancount" %>

using System;
using System.Web;
using System.Web.SessionState;
using TSqlServer;

public class getmymancount : IHttpHandler, IReadOnlySessionState
{
    
    public void ProcessRequest (HttpContext context) {
        
        string uid = context.Session["ecrm_uid"].ToString();

        context.Response.ContentType = "text/plain";
        context.Response.Write(CountMans(uid));
        context.Response.End();
    }

    private string CountMans(string uid)
    {
        string result = "";

        string sSql = "select infoid,infoname from t_sys_info2 where isshow='Y' and typeid='A01' order by orderby";
        TSqlDBReader myReader = new TSqlDBReader(sSql);
        while (myReader.FDataReader.Read())
        {
            string infoid = myReader.FDataReader.GetValue(0).ToString();
            string infoname = myReader.FDataReader.GetValue(1).ToString();

            result += "<a href=\"my_ecrm2.aspx?unitcode=" + infoid + "\">" + infoname + "(" + myCountMan(uid, infoid).ToString() + "人)</a>&nbsp;&nbsp;";
        }
        myReader.Free();

        return result;
    }

    private int myCountMan(string uid, string infoid)
    {
        int result = 0;

        string sSql = "select count(*) from t_linkman where status=0 and inman='" + uid + "' and unittype='" + infoid + "'";
        TSqlDBReader2 oRS = new TSqlDBReader2(sSql);
        if (oRS.FDataReader.Read())
        {
            result = (int)oRS.FDataReader.GetValue(0);
        }
        oRS.Free();

        return result;
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}